package com.li.utilstest.dialog

import android.content.Context
import android.view.View
import com.li.utilstest.R
import com.lxj.xpopup.core.CenterPopupView
import kotlinx.android.synthetic.main.center_dialog.view.*

/**
 *@PackageName: net.airice.iot.console.dialog
 *@Class: CenterDialog
 *@Author: lyg
 *@Date: 2021/6/23-13:38
 *@Description: 中部弹框
 */
class CenterDialog : CenterPopupView {
    private var title: String? = null
    private var content: String? = null

    constructor(context: Context) : super(context)
    constructor(context: Context, content: String) : this(context) {
        this.content = content
    }
    constructor(context: Context, title: String?, content: String) : this(context) {
        this.title = title
        this.content = content
    }


    override fun getImplLayoutId() = R.layout.center_dialog
    override fun onCreate() {
        super.onCreate()
        if(title?.isNotEmpty()==true){
            tv_title.visibility= View.VISIBLE
            tv_title.text = title ?: "提示"
        }
        tv_content.text = content ?: ""
        tv_cancel.setOnClickListener { this.dismiss() }
        tv_positive.setOnClickListener {
            onPositiveClick?.onClick()
            dismiss()
        }
    }

    var onPositiveClick: OnPositiveClick? =null
    fun setPositiveClick(positiveClick: OnPositiveClick) {
        this.onPositiveClick=positiveClick
    }
    interface OnPositiveClick {
        fun onClick()
    }

}